<template>
  <div class="jishi-container">
    <el-container class="full-height-container">
      <el-aside width="200px" class="sidebar">
        <el-menu
          active-text-color="#ffd04b"
          background-color="#545c64"
          class="el-menu-vertical-demo"
          :default-active="activeSubIndex"
          text-color="#fff"
          router
        >
          <el-sub-menu index="/jishi">
            <template #title>
              <el-icon><location /></el-icon>
              <span>计时管理</span>
            </template>
            <el-menu-item index="/JiShi/wodejishi">我的计时</el-menu-item>
            <el-menu-item index="/JiShi/jishiadd">计时添加</el-menu-item>
            <el-menu-item index="/JiShi/jishiyichang">计时异常管理</el-menu-item>
          </el-sub-menu>
          <el-sub-menu>
            <template #title>
              <el-icon><location /></el-icon>
              <span>计时审核</span>
            </template>
            <el-menu-item index="/JiShi/jishishenhejiu">计时审核(旧)</el-menu-item>
            <el-menu-item index="/JiShi/jishishenhe">计时审核</el-menu-item>
          </el-sub-menu>
          <el-sub-menu>
            <template #title>
              <el-icon><location /></el-icon>
              <span>计时报表</span>
            </template>
            <el-menu-item index="/JiShi/jishichaxun">计时查询</el-menu-item>
            <el-menu-item index="/JiShi/jishitongji">计时统计</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-main class="main-content"><router-view></router-view></el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

// 确保首次加载时也能选中默认子菜单
onMounted(() => {
  if (route.path === '/jishi') {
    router.push('/JiShi/wodejishi')
  }
})

const activeSubIndex = computed(() => {
  // 返回当前路径作为激活的菜单项
  return route.path
})
</script>

<style scoped>
.jishi-container {
  height: 100%;
  width: 100%;
}

.full-height-container {
  height: calc(100vh - 60px); /* 减去顶部导航栏的高度 */
  display: flex;
}

.sidebar {
  height: 100%;
  overflow-y: auto;
  background-color: #545c64;
}

.el-menu-vertical-demo {
  height: 100%;
  border-right: none;
}

.main-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* 确保el-menu占满侧边栏高度 */
.el-menu {
  height: 100% !important;
}

/* 防止内容溢出 */
:deep(.el-sub-menu .el-menu) {
  max-height: none;
}
</style>
